Type-safe run-time polytypic programming
نویسنده
چکیده
Polytypic programming is a way of defining type-indexed operations, such as map, fold and zip, based on type information. Run-time polytypic programming allows that type information to be dynamically computed—this support is essential in modern programming languages that support separate compilation, first-class type abstraction, or polymorphic recursion. However, in previous work we defined run-time polytypic programming with a typepassing semantics. Although it is natural to define polytypic programs as operating over first-class types, such a semantics suffers from a number of drawbacks. This paper describes how to recast that work in a type-erasure semantics, where terms represent type information in a safe manner. The resulting language is simple and easy to implement—we present a prototype implementation of the necessary machinery as a small Haskell library. 1 Polytypic programming Some functions are naturally defined by the type structure of their arguments. For example, a polytypic pretty printer can format any data structure by using type information to decompose it into basic parts. Without such a mechanism, one must write separate pretty printers for all data types and constantly update them as data types evolve. Polytypic programming simplifies the maintenance of software by allowing functions to automatically adapt to changes in the representation of data. Other classic examples of polytypic operations include reductions, comparison functions and mapping functions. The theory behind such operations has been developed in a variety of frameworks (Abadi et al., 1991; Abadi et al., 1995; Crary &Weirich, 1999; Dubois et al., 1995; Harper &Morrisett, 1995; Hinze, 2000; Jansson & Jeuring, 1997; Jay et al., 1998; Ruehr, 1998; Sheard, 1993; Trifonov et al., 2000; Wadler & Blott, 1989). Many of these frameworks generate polytypic operations at compile time through a source-to-source translation determined by static type information. In contrast, run-time polytypic programming (also called higher-order intensional type analysis (Weirich, 2002a)) defines polytypic operations with run-time analysis of dynamic type information. Run-time type analysis has two advantages over static forms of polytypism: First, run-time analysis may index polytypic operations by types that
منابع مشابه
Re ections on Instance
This paper examines the use of type-safe linguistic reeection in Haskell, a functional language. Several uses are identiied: providing an extensible system of instance derivation; extending derivation beyond type classes and providing a method for polytypic programming. A preprocessor for Haskell is presented that performs compile-time reeection upon type declarations in source code.
متن کاملHigher-Order Intensional Type Analysis in Type-Erasure Semantics
Higher-order intensional type analysis is a way of defining type-indexed operations, such as map, fold and zip, based on run-time type information. However, languages supporting this facility are naturally defined with a type-passing semantics, which suffers from a number of drawbacks. This paper, describes how to recast higher-order intensional type analysis in a type-erasure semantics. The re...
متن کاملPolytypic Functional Programming
Structural polymorphism is a generic programming technique known within the functional programming community under the names of polytypic or datatype-generic programming. In this thesis we show that such a technique conflicts with the principle of data abstraction and propose a solution for reconciliation. More concretely, we show that popular polytypic extensions of the functional programming ...
متن کاملPolytypic Syntax Tree Operations
Polytypic functional programming has the advantage that it can derive code for generic functions automatically. However, it is not clear whether it is useful for anything other than the textbook examples, and the generated polytypic code is usually too slow for real-life programs. As a real-life test, we derive a polytypic parser for the Haskell 98 syntax and look into other front-end compiler ...
متن کاملFormal polytypic programs and proofs
The aim of our work is to be able to do fully formal, machine verified proofs over Generic Haskellstyle polytypic programs. In order to achieve this goal, we embed polytypic programming in the proof assistant Coq and provide an infrastructure for polytypic proofs. Polytypic functions are reified within Coq as a datatype and they can then be specialized by applying a dependently typed term speci...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید
ثبت ناماگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید
ورودعنوان ژورنال:
- J. Funct. Program.
دوره 16 شماره
صفحات -
تاریخ انتشار 2006